//
//  UserAccoutTool.swift
//  WeiBo
//
//  Created by Tony on 2018/1/10.
//  Copyright © 2018年 Tony. All rights reserved.
//

import UIKit

class UserAccoutViewModel {
    
    // 单例
    static let shareInstance : UserAccoutViewModel = UserAccoutViewModel()
    
    // 普通属性
    var accout : UserAccout?
    
    // 计算属性
    var accoutPath : String {
        
        let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
        mySelfLog(documentPath!)
        return documentPath! + "/accout.plist"
    }
    
    // 计算属性
    var isLogin : Bool {
        if accout == nil {
            return false
        }
        
        guard let expires_date = accout?.expires_date  else {
            return false
        }
        
        return (expires_date.compare(Date()) == ComparisonResult.orderedDescending)
    }
    
    // init
    init() {
        accout = NSKeyedUnarchiver.unarchiveObject(withFile: accoutPath) as! UserAccout?
        
    }

}
